<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        body{
            box-sizing: border-box;
        }
        .fir{
            width: 500px;
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
        }
        .fir>div{
            width: 60px;
            height: 60px;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
        }
        .red{
            background-color: red;
        }
        .b1{
            /* display: none; */
            width: 30px;
            height: 30px;
            background-color: #fff;
        }
        .blue{
            background-color: blue;
        }
        .green{
            background-color: green;
        }
        .end{
            width: 1000px;
            height: 30px;
            margin: 50px auto;
            background-color: rgb(148, 146, 146);  
        }
        ul{
            display: flex;
            justify-content:space-between;
            line-height: 30px;
        }
        li{
            list-style: none;
        }
    </style>
</head>
<body>
    <div class="fir">
        <div class="red r1"><div class="r2"></div></div>
        <div class="blue r1"><div class="r2"></div></div>
        <div class="green r1"><div class="r2"></div></div>
    </div>
    <div class="end">
   <ul>
       <li>首页</li>
       <li>新闻</li>
       <li>头条</li>
       <li>热点</li>
       <li>播报</li>
   </ul>
    </div>
    <script>
        var r2 = document.querySelectorAll('.r1 div');
        var r1 = document.querySelectorAll('.r1');
        var body = document.querySelector('body');
        var ed = document.querySelector('.end');
        for(var i=0;i<r1.length;i++){
            r1[i].index=i;
            r1[i].onclick = function(){
                for(var j=0;j<r1.length;j++){
                    r2[j].classList.remove('b1');
                }
                r2[this.index].classList.add('b1');
                console.log(this.index);
                if(this.index==0){
                    body.style.backgroundColor = 'pink';
                    ed.style.backgroundColor = 'red';
                }else if(this.index==1){
                    body.style.backgroundColor = 'lightblue';
                    ed.style.backgroundColor = 'blue';
                }
                else if(this.index==2){
                    body.style.backgroundColor = 'lightgreen';
                    ed.style.backgroundColor = 'green';
                }
            }
        }
    </script>
</body>
</html>